package gui;

import processing.core.PApplet;
import processing.core.PFont;

public class ControlButton{

	/**
	 * 
	 */
	private int posX;
	private int posY;
	private int color;
	private String buttonText;
	private PFont font;
	
	private int textPosX;
	private int textPosY;
	
	private boolean selected;
	private boolean withText;
	
	public static final int SIZE = 20;
	
	private PApplet mainApplet;
	
	public ControlButton()
	{
		selected = false;
		withText = false;
	}
	
	public ControlButton(PApplet mainApplet, int posX, int posY, int color)
	{
		this();
		this.posX = posX;
		this.posY = posY;
		this.color = color;
		this.mainApplet = mainApplet;
	}
	
	public void setText(String text, int posX, int posY, PFont font)
	{
		this.buttonText = text;
		this.textPosX = posX;
		this.textPosY = posY;
		withText = true;
		this.font = font;
	}
	
	public void setSelected()
	{
		selected = true;
	}
	
	public void setUnselected()
	{
		selected = false;
	}
	
	public void drawButton()
	{
		mainApplet.stroke(color);
		if(selected)
		{
			mainApplet.fill(color);
		}
		else
		{
			mainApplet.noFill();
		}
		mainApplet.ellipse (posX, posY, SIZE, SIZE);
	}
	
	public boolean isSelected()
	{
		return selected;
	}
	
	public void drawText()
	{
		if(withText)
		{
			mainApplet.textFont(font);
			mainApplet.fill(0,0,0);
			mainApplet.text(buttonText, textPosX - 2, textPosY - 2);
			mainApplet.fill(color);
			mainApplet.text(buttonText, textPosX, textPosY);
		}
	}
	
	public boolean overPoint (){
		float disX = posX - mainApplet.mouseX;
		float disY = posY - mainApplet.mouseY;

		if(PApplet.sqrt(PApplet.sq(disX) + PApplet.sq(disY)) < SIZE/2) {
			return true;

		}else{
			return false;
		}
	}
}
